package com.example.myapplication.ui.screen


import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.example.myapplication.R

@Composable
fun LoginScreen(navController: NavController){
    //状态变量保存用户名和密码
    var username by remember { mutableStateOf("") }
    var password by remember { mutableStateOf("") }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(start = 16.dp, end = 16.dp, bottom = 16.dp),
        horizontalAlignment = Alignment.CenterHorizontally,
        verticalArrangement = Arrangement.Top
    ){
       Image(
           painter = painterResource(R.drawable.cat),
           contentDescription = "LOGO",
           modifier = Modifier.size(200.dp)
               .padding(top = 50.dp)
       )

        Text(
            text = "登录界面",
            fontSize = 30.sp,
            color = Color(0xff000000),
            fontWeight = FontWeight.Bold
        )

        Text(
            text = "登录账号以使用更多服务",
            fontSize = 18.sp,
            color = Color(0x66000000),
            fontWeight = FontWeight.Medium
        )

        Spacer(modifier = Modifier.height(30.dp))

        TextField(
            modifier = Modifier.fillMaxWidth(),
            colors = TextFieldDefaults. colors(
                unfocusedContainerColor = Color(0xFFFAF8FE),
                focusedContainerColor = Color(0xFFFAF8FE)
            ),
            placeholder = { Text("请输入用户名") },
            //label = { Text("请输入用户名")},
            value = username,
            onValueChange = {username = it}
        )

        Spacer(modifier = Modifier.height(20.dp))

        TextField(
            modifier = Modifier.fillMaxWidth(),
            colors = TextFieldDefaults. colors(
                unfocusedContainerColor = Color(0xFFFAF8FE),
                focusedContainerColor = Color(0xFFFAF8FE)
            ),
            placeholder =  { Text("请输入密码")},
            value = password,
            //label = { Text("请输入密码")},
            onValueChange = {password = it},
            visualTransformation = PasswordVisualTransformation()
        )

        Row(
            modifier = Modifier.fillMaxWidth().padding(
                top = 10.dp
            ),
            horizontalArrangement = Arrangement.Absolute.SpaceBetween
        ) {
            Text(
                text = "短信验证码登录",
                fontSize = 18.sp,
                color = Color(0xFF4879EE),
                fontWeight = FontWeight.Medium
            )

            Text(
                text = "忘记密码",
                fontSize = 18.sp,
                color = Color(0xFF4879EE),
                fontWeight = FontWeight.Medium
            )
        }

        Spacer(modifier = Modifier.height(150.dp))

        Button(
            modifier = Modifier.fillMaxWidth().height(50.dp).padding(start = 23.dp, end = 23.dp),
            colors = ButtonDefaults. buttonColors(
                contentColor = Color.White,
                containerColor = Color(0xFF4879EE)
            ),
            onClick = {/*TODO*/}
        ) {
            Text("登录")
        }

        Text(
            modifier = Modifier.padding(top = 10.dp),
            text = "注册账号",
            fontSize = 18.sp,
            color = Color(0xFF4879EE),
            fontWeight = FontWeight.Medium
        )


        Spacer(modifier = Modifier.fillMaxWidth().weight(1F))


        Text(
            modifier = Modifier.padding(top = 10.dp),
            text = "登录方式",
            fontSize = 14.sp,
            color = Color(0xffd5d5d5),
            fontWeight = FontWeight.Medium
        )

        Row(
            modifier = Modifier
                .fillMaxWidth(),

            horizontalArrangement = Arrangement.Absolute.SpaceEvenly
        ) {
            Box(
                contentAlignment = Alignment.Center,
                modifier = Modifier
                    .size(50.dp)
                    .border(width = 1.dp, color = Color.LightGray, shape = CircleShape)
            ){
                Text(
                    text ="方式一",
                    fontSize = 12.sp,
                    color = Color(0xffd5d5d5),
                )
            }

            Box(
                contentAlignment = Alignment.Center,
                modifier = Modifier
                    .size(50.dp)
                    .border(width = 1.dp, color = Color.LightGray, shape = CircleShape)
            ){
                Text(
                    text ="方式一",
                    fontSize = 12.sp,
                    color = Color(0xffd5d5d5),
                )
            }

            Box(
                contentAlignment = Alignment.Center,
                modifier = Modifier
                    .size(50.dp)
                    .border(width = 1.dp, color = Color.LightGray, shape = CircleShape)
            ){
                Text(
                    text ="方式一",
                    fontSize = 12.sp,
                    color = Color(0xffd5d5d5),
                )
            }
        }
    }
}